package yang.cn.com.greendaoapp.base;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.ButterKnife;
import yang.cn.com.greendaoapp.R;
import yang.cn.com.greendaoapp.bean.EventCenter;
import yang.cn.com.greendaoapp.utils.StatusBarUtil;

/**
 * Created by Administrator on 2017/5/27.
 */

public abstract class BaseActivity extends AppCompatActivity {
    public abstract void onEventComming(EventCenter var1);

    public abstract boolean isBindEventBusHere();

    //初始化view
    public abstract void initViewAndEvent();

    //获取布局文件
    public abstract int getLayoutId();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 无标题
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        // 设置竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(getLayoutId());
        StatusBarUtil.setTranslucentStatus(this, R.color.color_48baf3);
        if (this.isBindEventBusHere()) {
            EventBus.getDefault().register(this);
        }
        ButterKnife.bind(this);
        this.initViewAndEvent();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (this.isBindEventBusHere()) {
            EventBus.getDefault().unregister(this);
        }
        ButterKnife.unbind(this);
    }

    @Subscribe
    public void onEventMainThread(EventCenter eventCenter) {
        if (null != eventCenter) {
            this.onEventComming(eventCenter);
        }

    }

}
